// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import Tool from "../../framework/Tool";
import mainManage from "../../framework/mainManage";
import gameData from "../gameData";

const {ccclass, property} = cc._decorator;

@ccclass
export default class logoSevenDayLayer extends cc.Component {

    @property(cc.Node)
    dayNode: cc.Node[] = [];

    @property(cc.Button)
    close:cc.Button = null;


    //玩家当前登录的时间
    static nowTimesNum = 0;

    //玩家之前登录的时间
    static oldTimesNum = 0;

    //玩家当前登录的天数
    static loginDayNum = 0;

    //当前奖励是否获取
    static isGetValue = 0;

    titleList = ["","Mendapatkan apel : 5 ","Mendapatkan peran : Sun Wukong","Mendapatkan apel : 10 ",
    "Mendapatkan apel : 15 ","Mendapatkan peran : Manusia Bug","Mendapatkan apel : 20 ","Mendapatkan peran : Dewa perang goku "]

    awardList = [5,10,10,15,11,20,12]
    onLoad () {
        this.close.interactable = false;
        logoSevenDayLayer.getAward();
        if(logoSevenDayLayer.isGetValue == 0)
        {
            for(let i = 0; i< logoSevenDayLayer.loginDayNum; i++)
            {
                this.dayNode[i].getChildByName("meng").active = true;
            }
            logoSevenDayLayer.isGetValue = 1;
            logoSevenDayLayer.loginDayNum ++;
            logoSevenDayLayer.saveLoginDay();
            logoSevenDayLayer.saveAward();
            if(logoSevenDayLayer.loginDayNum == 1 || logoSevenDayLayer.loginDayNum == 3 || logoSevenDayLayer.loginDayNum == 4 || logoSevenDayLayer.loginDayNum == 6)
            {
                gameData.addSinglePumpkin(this.awardList[logoSevenDayLayer.loginDayNum - 1])
            }
            else if(logoSevenDayLayer.loginDayNum == 2 || logoSevenDayLayer.loginDayNum == 5 || logoSevenDayLayer.loginDayNum == 7)
            {
                gameData.saveRoleSkin(this.awardList[logoSevenDayLayer.loginDayNum - 1])
            }
            this.dayNode[logoSevenDayLayer.loginDayNum - 1].getChildByName("kuang").active = true;
            mainManage.createToast(this.titleList[logoSevenDayLayer.loginDayNum]);
            this.scheduleOnce(()=>{
                this.close.interactable = true;
                this.dayNode[logoSevenDayLayer.loginDayNum - 1].getChildByName("kuang").active = false;
                this.dayNode[logoSevenDayLayer.loginDayNum - 1].getChildByName("meng").active = true;
            },1.5)
        }else{
            this.close.interactable = true;
            for(let i = 0; i< logoSevenDayLayer.loginDayNum; i++)
            {
                this.dayNode[i].getChildByName("meng").active = true;
            }
        }
    }

    start () {
        

    }

    clickClose()
    {
        this.node.destroy();
    }

    static getNowTimes()
    {
        this.nowTimesNum = Math.floor(new Date().getTime() / 1000)
    }

    static saveLoginTime(){
        Tool.saveData("loginTime",this.nowTimesNum);
    }

    static getLoginTime(){
        let data = Tool.getData("loginTime");
        if(data != null && data != "" && data != undefined){
            this.oldTimesNum = parseInt(data);
        }else{
            this.oldTimesNum = 0;
        }
    }

    static saveLoginDay(){
        Tool.saveData("loginDay",this.loginDayNum);
    }

    static getLoginDay(){
        let data = Tool.getData("loginDay");
        if(data != null && data != "" && data != undefined){
            this.loginDayNum = parseInt(data);
        }else{
            this.loginDayNum = 0;
        }
    }

    static saveAward(){
        Tool.saveData("getValue",this.isGetValue);
    }

    static getAward(){
        let data = Tool.getData("getValue");
        if(data != null && data != "" && data != undefined){
            this.isGetValue = parseInt(data);
        }else{
            this.isGetValue = 0;
        }
    }


    // update (dt) {}
}
